package com.hzit.user.controller;

import com.hzit.user.service.IUserService;
import com.hzit.user.vo.UserVo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.Brand;
import com.ruoyi.system.api.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Controller
@RequestMapping
public class UserController {

	@Autowired
	private IUserService userService;

	@GetMapping("/list")
	@ResponseBody
	public R list(){
		List<User> list = userService.list();
		return R.ok(list);
	}
	// 默认页面
	@GetMapping({"/","/register.html"})
	public String register(Model model){

		return "register";
	}
	// 查询用户时携带请求头(test=hello)去到hzit-manager服务中查询品牌列表
	@GetMapping("/listBrand")
	@ResponseBody
	public R listBrand(){
		return userService.findBrands();
	}
	// 根据手机号生成验证码
	@GetMapping("/user/getCode/{phone}")
	public String createCode(@PathVariable String phone){
		userService.createCode(phone);
		return "register";
	}
	// 添加用户
	@PostMapping("/user/add")
	public String add(UserVo vo){
		boolean add = userService.add(vo);
		return "register";
	}
	// 添加用户的同时添加品牌
	@GetMapping("/user/brand/save")
	@ResponseBody
	public R addUserAndBrand(){
		userService.addUserAndBrand();
		return R.ok();
	}
}
